

function say() {
    alert("1608. 特殊数组的特征值");
}
say();


/**
 * @param {number[]} nums
 * @return {number}
 */
var specialArray = function (nums) {
    var res = 1
    var max = nums.length

    var count = 0
    while (res <= max) {
        for (var i = 0; i < max; i++) {
            if (nums[i] >= res) {
                count++
            }
        }
        if (count == res) {
            return res
        } else if (count > res) {
            res++
            count = 0
        } else { // count < res
            return -1
        }
    }
};
